﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SQLite.NET;

namespace BierdopjeTV.Database
{
    class GUISeasons
    {
        public int Season;
        public int Episodes;
        public int SubsNL;
        public int SubsEN;
        public int Watched;
        public int Downloaded;

    }

    static class DBSeasons
    {

        public static List<GUISeasons> getSeasons(int ShowID)
        {
            List<GUISeasons> _Seasons = new List<GUISeasons>();

            GUISeasons _Season;

            string _Query = "SELECT * FROM LocalSeasons WHERE ShowID = '" + ShowID.ToString() + "';";

            SQLiteResultSet _Result = Helpers.SqliteHelper.ExecuteQuery(_Query);

            for (int i = 0; i < _Result.Rows.Count; i++)
            {
                _Season = new GUISeasons();
                _Season.Season = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["Season"]]);
                _Season.Episodes = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["AantalEpisodes"]]);
                _Season.SubsNL = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["SubsNL"]]);
                _Season.SubsEN = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["SubsEN"]]);
                _Season.Watched = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["AantalGezien"]]);
                _Season.Downloaded = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["AantalEpisodes"]]);
                //We have seen 12 of 10 downloaded episodeS? ;-)
                if (_Season.Watched > _Season.Downloaded)
                {
                    _Season.Watched = _Season.Downloaded;
                }

                _Seasons.Add(_Season);
                _Season = null;

            }

            return _Seasons;

        }
    }
}
